package mrusanov.team

import mrusanov.player.Player
import mrusanov.staff.Coach
import mrusanov.player.psychology.{ Friendship, Conflict }
import mrusanov.elo.TeamEloRating
import mrusanov.battle.Battle
import java.util.Date

class Team(val club: Club, val name: String, val teamLevel: TeamLevel) {
	var roster = Vector[Player]()
	def coach = club.clubStaff.coach2teams(teamLevel)
	val rating = new TeamEloRating()

	override def toString = name

	def relaxOneDay(now: Date) {
		roster foreach (_.relaxOneDay(now))
	}

	def removePlayer(player: Player): Boolean = {
		val sizeBefore = roster.size
		roster = roster.filterNot(_ == player)
		sizeBefore != roster.size
	}

	def calculatePlayersRelations() {
		val conflicts = Conflict.newConflicts(roster)
		val friendships = Friendship.newFriendships(roster)

		conflicts foreach (_.startConflict())
		friendships foreach (_.startFriendship())
	}

	def playersForMatch: Vector[Player] = {
		roster.filterNot(_.isInjured).take(Battle.PLAYERS_COUNT)
	}
}
